﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using VCN.App.DataTransferObjects;
using System.Data;
using System.Data.SqlClient;

namespace VCN.App.DataAccessLayer
{
    public class ImageSlideDAO : BasicDAO<ImageSlide>
    {
        public static ImageSlide Convert(DataRow ip_dr)
        {
            ImageSlide v_dl_obj = new ImageSlide();
            v_dl_obj.Id = int.Parse(ip_dr["Id"].ToString());            
            v_dl_obj.Image = ip_dr["Image"].ToString();
            v_dl_obj.Order = int.Parse(ip_dr["Order"].ToString());
            return v_dl_obj;
        }

        public DataTable Select(int ip_Id)
        {
            return exeSpSelectById("[sp_tblImageLogo_SelectByID]", ip_Id);
        }

        public DataTable SelectByPro(int ip_type)
        {
            if (ip_type == 1)
                return exeSpSelect("[sp_tblImageLogoSlide_SelectDisp]");
            else if (ip_type == 0)
                return exeSpSelect("[sp_tblImageLogoSlide_SelectNotDisp]");
            else return exeSpSelect("[sp_tblImageLogoSlide_SelectAll]");
        }
        // Lay hinh anh theo thu tu hien thi
        public DataTable SelectByOrder(int ip_no)
        {            
            DataTable op_dt = new DataTable();
            SqlConnection v_conn = BasicDAO<BasicObject>.GetConnection();
            SqlCommand v_comm = new SqlCommand("[sp_tblImageLogo_SelectByOrder]", v_conn);
            v_comm.CommandType = CommandType.StoredProcedure;
            v_comm.Parameters.Add("@Order", SqlDbType.Int).Value = ip_no;
            SqlDataAdapter adapter = new SqlDataAdapter(v_comm);
            adapter.Fill(op_dt);
            v_conn.Close();
            return op_dt;
        }
        public bool Insert(ImageSlide ip_img_obj)
        {
            if (ExecuteNonQuery("sp_tblImagesSlideHome_Insert",
                "@IMAGE", ip_img_obj.Image,
                "@ORDER", ip_img_obj.Order) > 0)
                return true;
            else
                return false;
        }

        public override bool insert(VCN.App.DataTransferObjects.ImageSlide ip_obj)
        {
            throw new NotImplementedException();
        }
        public override bool update(ImageSlide ip_obj)
        {
            if (ExecuteNonQuery("sp_tblImagesSlideHome_Update",
                "@Id" , ip_obj.Id,
                "@Image", ip_obj.Image,
                "@Order", ip_obj.Order) > 0)
                return true;
            else
                return false;
        }

        public override List<ImageSlide> selectAll2List(ImageSlide ip_obj)
        {
            throw new NotImplementedException();
        }
    }
}
